package com.example.demo2

import android.content.Context
import android.graphics.Color
import android.util.Log
import android.view.ViewGroup
import android.widget.LinearLayout
import androidx.recyclerview.widget.RecyclerView
import io.zhuozhuo.remotetestlib.Message

class MessageListAdapter(private val mContext: Context, private val mList: MutableList<Message>) :
    RecyclerView.Adapter<MessageListAdapter.ViewHolder>() {

    inner class ViewHolder(private val messageView: MessageView) :
        RecyclerView.ViewHolder(messageView) {
        fun getView(): MessageView {
            return messageView
        }
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = MessageView(mContext)
        val lp = LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT,
            100
        )
        view.layoutParams = lp
        return ViewHolder(view)
    }

    override fun getItemCount(): Int {
        return mList.size
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        Log.d("rv", position.toString())
        holder.getView().setBackgroundColor(if (position / 2 == 0) Color.RED else Color.BLACK)
    }
}